import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {
    ActivityClassify,
    ActivityFilterModel
} from "../../../model/pages/activity/activity-filter/activity-filter.model";
import moment from 'moment';

@Injectable()
export class ActivityListProvider {

    constructor(private http: HttpClient) {
    }

    /**
     * 获取活动列表
     * @param {ActivityFilterModel} filter
     * @param {number} notLoading
     * @returns {Observable<Object>}
     */
    getActivityList(filter: ActivityFilterModel,
                    notLoading = 0) {
        let url = `/campaign/v1/app/list?notLoading=${notLoading}`;
        url += `&classify=${filter.classify}`;
        url += filter.startTime ? `&startTime=${moment(filter.startTime).unix()}` : '';
        url += filter.endTime ? `&endTime=${moment(`${filter.endTime} 23:59:59`).unix()}` : '';
        filter.type.forEach((type) => {
            url += `&type=${type}`;
        });
        filter.status.forEach((status) => {
            url += `&status=${status}`;
        });
        return this.http.get(url);
    }

    /**
     * 获取预览活动列表
     * @returns {Observable<Object>}
     */
    getPreviewList(classify, notLoading) {
        return this.http.get(`/campaign/v1/app/manager/list?notLoading=${notLoading}&classify=${classify}`);
    }

    /**
     * 获取不同类别活动下的活动类别
     * @returns {Observable<Object>}
     */
    getActivityType(classify, notLoading=1) {
        return this.http.get(`/campaign/v1/app/campaignType?notLoading=${notLoading}&classify=${classify}`);
    }
}


